use crate::dto::core::network_acl_rule::{NetworkAclRuleAction, NetworkAclRuleProtocol};
use serde::{Deserialize, Serialize};
use validator::Validate;
use wanmesh_common::util::deserialize_some;

#[derive(Serialize, Deserialize, Validate, Debug, Clone)]
pub struct AddParams {
    #[serde(default)]
    pub description: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub protocol: Option<NetworkAclRuleProtocol>,
    pub action: NetworkAclRuleAction,
    pub src_ip_address: cidr::IpInet,
    pub dst_ip_address: cidr::IpInet,
}

#[derive(Serialize, Deserialize, Validate, Default, Debug, Clone, Eq, PartialEq)]
pub struct UpdateParams {
    pub description: Option<String>,
    #[serde(default, deserialize_with = "deserialize_some")]
    pub protocol: Option<Option<NetworkAclRuleProtocol>>,
    pub action: Option<NetworkAclRuleAction>,
    pub src_ip_address: Option<cidr::IpInet>,
    pub dst_ip_address: Option<cidr::IpInet>,
}

#[derive(Serialize, Deserialize, Validate, Debug, Clone, Eq, PartialEq)]
pub struct Filter {
    pub network_acl_id: Option<String>,
}
